package com.export.document.controller;

import com.export.document.entity.ExportRecord;
import com.export.document.service.ReadDBService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/read")
@Log4j2
public class ReadDBController {
    @Autowired
    private ReadDBService readService;

    @GetMapping("/test")
    public String test() {
        log.info("日志测试行不行");
        return "test success";
    }

    @GetMapping("/dbTest")
    public List<ExportRecord> dbTest() {
        log.info("读取测试行不行");
        List<ExportRecord> result = readService.dbTest();
        return result;
    }

    /**
     * 读取数据库
     *
     * @return
     */
    @PostMapping("/readDB")
    public List<Map<String, Object>> readDB() {
        log.info("读取数据库");
        List<Map<String, Object>> result = readService.readDB();
        return result;
    }

    /**
     * 读取数据库表
     *
     * @param shcemaName
     * @return
     */
    @PostMapping("/readTables")
    public List<Map<String, Object>> readTables(String shcemaName) {
        log.info("读取数据库表shcemaName:{}", shcemaName);
        List<Map<String, Object>> result = readService.readTables(shcemaName);
        return result;
    }

    /**
     * 读取数据库表
     *
     * @param tableName
     * @return
     */
    @PostMapping("/readColumns")
    public List<Map<String, Object>> readColumns(String shcemaName, String tableName) {
        log.info("读取数据库表tableName:{}", tableName);
        List<Map<String, Object>> result = readService.readColumns(shcemaName, tableName);
        return result;
    }

}
